package objects;

import java.util.List;
import java.util.Random;


public class Deck {

	private List<Card> cards;

	/**
	 * The creation of the deck - the only time we put cards in it
	 */
	public Deck(List<Card> cards)
	{
		this.cards = cards;
	}
	
	/**
	 * The creation of the deck - the only time we put cards in it
	 */
	public Deck()
	{
	}
	
	/**
	 * This method draw a card from the deck using random access.
	 * (instead of creating a shuffling method) for dealing each time differently	
	 * @return the card from the deck
	 */
	public Card drawFromDeck()
	{
		Random generator = new Random();
	
	    int index= generator.nextInt( cards.size() );
	
	    return cards.remove(index);
	}
	
	/**
	 * The method find a card by it's name
	 * @param name
	 * @return
	 */
	public Card drawFromDeckByName(String name)
	{
		for (Card card : cards) {
			if (card.getName().equals(name))
			{
				return cards.remove(cards.indexOf(card));
			}
		}
		
		return null;
	}

	
	public List<Card> getCards() {
		return cards;
	}
}
